package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.pojo.Member;
import com.itheima.pojo.Result;
import com.itheima.service.MemberService;
import com.itheima.utils.JedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;


@RestController
@RequestMapping("/member")
public class MemberController {

    @Autowired
    JedisUtil jedisUtil;

    @Reference
    MemberService memberService;

    @RequestMapping("/getFamily")
    public Result getFamily(@com.itheima.interceptor.Member Member member){
        //根据当前登录用户id查询用户的家庭联系人
        List<Member> members = memberService.getFamily(member.getId());

        return Result.success("",members);
    }

    @RequestMapping("/getUserMessage")
    public Result getUserMessage(@com.itheima.interceptor.Member Member member){
        Member members = memberService.findMemberById(member.getId());
        return Result.success("",members);
    }

    @RequestMapping("/addFamily")
    public Result addFamily(@RequestBody Member member){
        try {
            Member members = memberService.addFamily(member);
            return Result.success("添加成功",members);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.success("添加失败");
        }

    }

    @RequestMapping("/editFamily")
    public Result editFamily(@com.itheima.interceptor.Member Member member){
        //根据当前登录用户id查询用户的家庭联系人
        List<Member> family = memberService.editFamily(member.getId());

        return Result.success("",family);
    }


}
